package com.hdoit.ares.selfcommon.utils;


public class MathRewardUtil {
	/**
	 * 0出现的概率为%0
	 */
	public static double rate0 = 0.0;
	/**
	 * 1出现的概率为%90
	 */
	public static double rate1 = 0.95;
	/**
	 * 2出现的概率为%6
	 */
	public static double rate2 = 0.0;
	/**
	 * 3出现的概率为%4
	 */
	public static double rate3 = 0.01;
	/**
	 * 4出现的概率为%0
	 */
	public static double rate4 = 0.0;
	/**
	 * 5出现的概率为%0
	 */
	public static double rate5 = 0.0;
	/**
	 * 6出现的概率为%6
	 */
	public static double rate6 = 0.04;
	/**
	 * Math.random()产生一个double型的随机数，判断一下 例如1出现的概率为%90，则介于0到0.90中间的返回1
	 * 
	 * @return int
	 * 
	 */
	private int PercentageRandom() {
		double randomNumber;
		randomNumber = Math.random();
		if (randomNumber >= 0 && randomNumber <= rate0) {
			return 0;
		} else if (randomNumber >= rate0 && randomNumber <= rate0 + rate1) {
			return 1;
		} else if (randomNumber >= rate0 + rate1 && randomNumber <= rate0 + rate1 + rate2) {
			return 2;
		} else if (randomNumber >=rate0 + rate1 + rate2 && randomNumber <= rate0 + rate1 + rate2 + rate3) {
			return 3;
		}
		else if (randomNumber >= rate0 + rate1 + rate2 +rate3 && randomNumber <= rate0 + rate1 + rate2 + rate3 + rate4) {
			return 4;
		}
		else if (randomNumber >= rate0 + rate1 + rate2 + rate3 + rate4 && randomNumber <= rate0 + rate1 + rate2 + rate3 + rate4 + rate5) {
			return 5;
		}
		else if (randomNumber >= rate0 + rate1 + rate2 + rate3 + rate4 + rate5 && randomNumber <= rate0 + rate1 + rate2 + rate3 + rate4 + rate5 + rate6) {
			return 6;
		}
		return -1;
	}

	/**
	 * 测试主程序
	 * 
	 * @param agrs
	 * @return 
	 */
	public static int main() {
		// java.lang.Math.random() 返回一个正符号的double值，大于或等于0.0且小于1.0
		MathRewardUtil a = new MathRewardUtil();
		
		return a.PercentageRandom();
	}
}
